package com.rinlink.gateway.jt808.common;

import com.google.common.collect.Maps;
import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.util.LinkedHashMap;

@Data
@Accessors(chain = true)
@ToString
public class CommonResult<T> {

    private String code;

    private String message;

    private T data;

    private CommonResult(){}

    public static <T> CommonResult<T> of(StatusCode code,String msg,T data){
        return new CommonResult<T>().setData(data).setMessage(msg).setCode(code.value());
    }


    public static CommonResult of(CommonStatusCode code){
        return new CommonResult().setCode(code.name()).setMessage(code.getDesc()).setData(new LinkedHashMap());
    }

    public static <T> CommonResult<T> success(T t){
        return of(CommonStatusCode.SUCCESS,CommonStatusCode.SUCCESS.getDesc(),t);
    }


}
